package service.impl;

import pojo.User;
import dao.UserDao;
import dao.impl.UserDaoImpl;
import service.UserService;

public class UserServiceImpl implements UserService {
	
	private UserDao userDao;
	
	public UserServiceImpl() {
		userDao = new UserDaoImpl();
	}

	@Override
	public boolean login(String name, String password) {
		User u = userDao.loadUser(name);
		return u != null && u.getPassword().equals(password);
	}

	@Override
	public boolean register(String name, String password) {
		User u = userDao.loadUser(name);
		if (u != null) {
			// user already exists
			return false;
		}
		userDao.addUser(new User(null, name, password));
		return true;
	}

}
